﻿using System;
using System.Data;
using System.Configuration;
using Token.Util;

namespace Token.Piker.Core.Security
{
    /// <summary>
    /// 加密解密实例工厂
    /// </summary>
    public class EncryptionProviderFactory
    {
        /// <summary>
        /// 默认的加密解密类 名
        /// </summary>
        private static readonly string defaultEncryptorType = "Security.DES";
        /// <summary>
        /// 不可实例化此类
        /// </summary>
        private EncryptionProviderFactory()
        {

        }

        public static IEncrypt GetEncryptor()
        {

            string strType = ConfigurationManager.AppSettings["security.EncryptionProvider"] as string;

            if (string.IsNullOrEmpty(strType)){
                
                strType = defaultEncryptorType;
                
                LogHelper.Warn("未配置security.EncriptionProvider，将使用“Security.DES”类作为字符串加密、解密工具。");

            }

            Type type = Type.GetType(strType, true);

            IEncrypt instance = Activator.CreateInstance(type) as IEncrypt;

            return instance;
        }
    }
}